import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
import personalChildren from './personal.js'
import VueCookies from 'vue-cookies'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/personal',
    name: 'Personal',
    redirect:'/bookClass/ClassList',
    component: () => import( '../views/Personal.vue'),
    children:personalChildren
  },
  {
    path: '/login',
    name: 'login',
    component: () => import( '../views/Login.vue')
  },
  {
    path: '/rigster',
    name: 'rigster',
    component: () => import( '../views/Rigster.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to,from,next)=> {
  if(to.name == "login" || to.name == "Rigster") {
    next()
  }
  if(VueCookies.isKey('Authorization')) {
    next()
  }else {
    next({
      name:"login"
    })
  }
})

export default router
